package com.dd.probe.common.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
@author bigbigmeng
@createTime 2024/11/5 17:36
@instruction 统一返回相应类
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("统一信息返回类")
public class Result<T> {
    @ApiModelProperty("状态码")
    int code;
    @ApiModelProperty("提示信息")
    String message;
    @ApiModelProperty("数据")
    T data;

    public static Result success() {
        return new Result(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), null);
    }

    /**
     * 不带数据的异常返回
     */
    public static Result error(int code, String message) {
        return new Result(code, message, null);
    }

    /**
     * 不带数据的异常返回
     */
    public static Result error(String message) {
        return new Result(500, message, null);
    }

    /**
     * 返回数据为Integer类型
     */
    public static <T> Result<T> success(ResultEnum resultEnum, T t) {
        return new Result(resultEnum.getCode(), resultEnum.getMessage(), t);
    }
}
